import { AppCTX } from "../../types/koaExtend";
import Router from "koa-router";
import {
  getBrandWithExtAndStatAndEndorsementForUser,
  getBrandExtByBrandID,
} from "../../service/brandService";
import { isString, isUndefined, _pick } from "mmb";
const router = new Router();

// 获取品牌信息
router.get("/usr/brand/:brandId", async (ctx: AppCTX, next) => {
  const { userId } = ctx;
  const { brandId } = ctx.params;
  const { brandWithExtAndStatAndEndorsement, activityAsFeatureAvailables } =
    await getBrandWithExtAndStatAndEndorsementForUser(brandId, userId);
  ctx.body = {
    ..._pick(
      brandWithExtAndStatAndEndorsement,
      "id",
      "name",
      "pic",
      "intro",
      "homepageBg",
      "fansCount",
      "publishActivityCount",
      "isDistributionEntranceDisplay",
      "distributorId",
      "isEndorsementEntranceDisplay",
      "endorseSpokesmanId"
    ),
    activityAsFeatureAvailables,
  };
});

// 获取品牌配置
router.get("/usr/brand/:brandId/cfg", async (ctx: AppCTX, next) => {
  const { userId } = ctx;
  const { brandId } = ctx.params;
  const brandExt = await getBrandExtByBrandID(brandId);
  console.log("brandExt:", brandExt);
  ctx.body = {
    ..._pick(brandExt!, "isWxpayAvailable"),
  };
});

export default router;
